package com.allen.module_main

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager.widget.PagerAdapter
import com.allen.common.WorkBean


/**
 *  @Autor  lwl
 *  日期    2021/4/7
 *  目的
 */
@Suppress("UNREACHABLE_CODE")
class WorkViewPagerAdapter(context:Context, list: ArrayList<ArrayList<WorkBean>>) : PagerAdapter() {
    var ctx:Context?=null
    var lists: ArrayList<ArrayList<WorkBean>> = ArrayList()
    var recyclerViews: ArrayList<RecyclerView> = ArrayList()
    init {
        ctx= context
        lists.addAll(list)
        initRecy()
    }
    fun initRecy(){
        for(bean: ArrayList<WorkBean>  in lists){
            var view =
                LayoutInflater.from(ctx).inflate(R.layout.module_work_banner_recy,null)

            var recyclerView = view.findViewById<RecyclerView>(R.id.module_work_banner_recy)
            var pair: ViewGroup.LayoutParams = ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT
            )
//            recyclerView.setIn
            recyclerView.layoutParams = pair
            recyclerView.layoutManager = GridLayoutManager(ctx,4)
            recyclerView.adapter = ModuleWorkBannerAdapter(bean)
            recyclerViews.add(recyclerView)
        }

    }
    override fun destroyItem(container: ViewGroup, position: Int, view: Any) {
        container.removeView(recyclerViews[position])
    }


    override fun isViewFromObject(view: View, view2: Any): Boolean {
        return view == view2;//官方提示这样写
    }

    override fun getCount(): Int {
        return lists.size
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        container.addView(recyclerViews[position])
        return recyclerViews[position]
    }
}